import xlwt
import xlrd


class TxtTranslateExcel:
    def __init__(self):
        self.__excel_title = []
        self.__sheet = "" #设置sheet页的名字
        self.__path = []
        self.__workbook = None

    def set_path(self, value):
        self.__path = value
        # 创建excel表的名字
        self.__workbook = xlwt.Workbook()
        return

    def save_excel(self):
        self.__workbook.save(self.__path)

    def write_excel(self, sheet, titles, value, summary=None):
        worksheet = self.__workbook.add_sheet(sheet)
        # 创建表头
        for i in range(0, len(titles)):
            worksheet.write(0, i, titles[i])
        row = 1
        for num in range(0, len(value)):
            for index in range(0, len(value[num])):
                worksheet.write(num + 1, index, value[num][index])
                row = num + 1
        if summary is not None:
            for sum_ in range(0, len(summary)):
                worksheet.write(row + 1, sum_, summary[sum_])







if __name__ == '__main__':
    title_list = ["index", "file_path", "offline_asr", "offline_start", "offline_end",
                  "online_asr", "online_start", "online_end"]
    path = r"C:\Users\1\Desktop\output.xls"
    data_list = [['5-5', '/data1/liutianwei/audio_files/1_output.wav', '下个月有没有雨', 2920, 4780, '下个月有没有雨', 2920, 4500], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '查看整条路线', 9610, 12070, '查看整条路线', 10720, 12340], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '结束导航', 18010, 19030, '结束导航', 18240, 19220], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', ' 取消全程搜索', 25060, 26920, '取消全局搜索', 25360, 26940], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '明天上午的天气', 32530, 34510, '明天上午的天气', 32880, 34580], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '最近的停车场', 40150, 41860, '最近的停车场', 40520, 41980], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '最近的停车场', 40150, 41860, '最近的洗车房', 65840, 67660], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '最近的洗车房', 45430, 47170, '最近的停车场', 40520, 41980], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '最近的洗车房', 45430, 47170, '最近的洗车房', 65840, 67660], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '取消系统升级', 82900, 54700, '取消系统设置', 73240, 74980], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '取消系统升级', 82900, 54700, '开启系统升级', 220840, 222460], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '关闭路况', 89530, 61750, '关闭路况', 80800, 81820], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '关闭天窗', 103780, 105430, '关闭天窗起翘', 95040, 96540], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '未来几个小时会下雨吗', 111970, 114610, '未来几个小时会下雨吗', 102520, 104860], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '调高一点香氛', 130240, 131920, '调高一点香氛', 118360, 119860], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '调高一点香氛', 130240, 131920, '调高一点 香氛', 140800, 142300], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '还剩多少', 136750, 139000, '还剩多少', 148160, 149220], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '启东路况', 144700, 146110, '启动路况', 155320, 156300], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '回拨电话', 180940, 152710, '回拨电话', 162440, 163460], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '回拨电话', 180940, 152710, '回拨电话', 206420, 207340], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', ' 启用中心', 190840, 192430, '开启应用中心', 191440, 192940], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '关闭套餐管理', 198040, 199900, '关闭套餐管理', 198800, 200380], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '回拨电话', 204730, 206470, '回拨电话', 162440, 163460], ['5-5', '/data1/liutianwei/audio_files/1_output.wav', '回拨电话', 204730, 206470, '回拨电话', 206420, 207340]]
    TxtTranslateExcel = TxtTranslateExcel()
    TxtTranslateExcel.set_path(path)
    TxtTranslateExcel.write_excel("1", title_list, data_list)
    TxtTranslateExcel.save_excel()
    print("生成完成")
